/**
XenSim simulates xenbal.
Copyright (C) 2006 Travis Vachon

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
package xensim;
import java.util.Random;
public class CPUGaussFn implements CpuFn {
	
	double Hz;
	double mean;
	double stand_dev;
	Random generator;

	public CPUGaussFn(long mHz, double mean, double stand_dev){
		assert mean <= 1;
		assert mean >= 0;
		generator = new Random(System.nanoTime()*this.hashCode());
		this.mean = mean;
		this.stand_dev = stand_dev;
		this.Hz = mHz*1000000;
		
	}
	
	public long cyclesPerSecond(double time) {
		// TODO Auto-generated method stub
		return (long)(Hz * Math.max(0.0, Math.min(1.0,generator.nextGaussian()*stand_dev + this.mean)));
		
	}

	public long cyclesUsed(double startTime, double stopTime) {
		// We're going to assume a constant rate during any length of time
		return (long)(this.cyclesPerSecond(startTime)*(stopTime-startTime)/SimGlobals.TIME_CONSTANT);
	}

}
